#ifndef WIFI_MANAGER_H
#define WIFI_MANAGER_H

#include "cJSON.h"
#include "esp_err.h"
#include "esp_http_server.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "led_manager.h"
#include "led_manager_adapter_espidf.h"
#include "nvs.h"
#include "nvs_flash.h"
#include <stdbool.h>
#include <stdint.h>

#define MAX_RPC_METHODS 8

typedef enum {
	WIFI_EVENT_CONNECTED,
	WIFI_EVENT_DISCONNECTED,
	WIFI_EVENT_FAILED,
} wifi_manager_event_t;

// 回调函数改为带上下文参数
typedef void (*wifi_manager_event_cb_t)(wifi_manager_event_t event, void* user_ctx);

typedef struct {
	gpio_num_t config_button_pin;
	char wifi_ssid[64];
	char wifi_pass[64];
	unsigned long button_press_time;
	httpd_handle_t server;
} DeviceConfig;

#ifdef __cplusplus
extern "C" {
#endif
void launch_wifi_ap_with_web_config(void);
void wifi_manager_begin(void);
void wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base,
						int32_t event_id, void *event_data);
esp_err_t wifi_manager_register_event_cb(wifi_manager_event_cb_t cb, void* user_ctx);

bool wifi_manager_is_config_mode(void);
bool wifi_manager_is_connected(void);

#ifdef __cplusplus
}
#endif

#endif // WIFI_MANAGER_H
